/*
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Authors:
 *  	Albert Marieges Garcia
 *  	Álex Pardo Fernández
 *  	Enric Mayas Márquez
 *  	Juan Carlos Calvo Tejedor
 *  	Marc Gironés Dezsényi
 *  
 *  Contact:
 *  	bcn.tours.android@gmail.com
 *  Webpage:
 *  	bcntours.co.cc
 *
 */
package com.BCNTours.AR.Vista;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.DisplayMetrics;
import android.view.View;

import com.BCNTours.R;

/**
 * This class draws an objects on the screen, which indicates the state of the gps connection.
 */
public class DrawSignal extends View { 
	@SuppressWarnings("unused")
	private float width;
	private float height;
	private int numBitmap = R.drawable.red;
	
	/**
	 * Constructor of the class
	 * @param context
	 */
    public DrawSignal(Context context) { 
            super(context); 
            // TODO Auto-generated constructor stub
    } 
    
    @Override 
    protected void onDraw(Canvas canvas) { 
    	
            // TODO Auto-generated method stub 
    		width = canvas.getWidth();
    		height = canvas.getHeight();
            Paint paint = new Paint(); 
            paint.setStyle(Paint.Style.FILL); 
            paint.setColor(Color.DKGRAY); 
            if(canvas.getDensity() == DisplayMetrics.DENSITY_MEDIUM){
				paint.setTextSize(paint.getTextSize() + 3);
			}else if(canvas.getDensity() == DisplayMetrics.DENSITY_HIGH){
				paint.setTextSize(paint.getTextSize() + 6);
			}
            canvas.drawRect(10, height - 20, 50, height, paint);
            Bitmap eBitmap = BitmapFactory.decodeResource(getResources(), numBitmap);
            paint.setColor(Color.WHITE); 
            canvas.drawText("GPS", 10, height-5, paint);
            canvas.drawBitmap(eBitmap ,35,height-15,  null) ;
            super.onDraw(canvas); 
    } 
    
    @Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    	// TODO Auto-generated method stub
    	setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
    }
    
    /**
     * Draw the signal, which symbolizes the status of the GPS
     * @param strength Represents the strength of the signal
     */
    public void drawSignal(int strength){
    	switch(strength){
    		//no signal
    		case 0:
    			numBitmap = R.drawable.red;
    			invalidate();
    			break;
    		//low signal
    		case 1:
    			numBitmap = R.drawable.orange;
    			invalidate();
    			break;
    		//high signal
    		case 2:
    			numBitmap = R.drawable.green;
    			invalidate();
    			break;
    		default:
    			break;
    	}
    }
} 